package com.yjxxt;

import com.yjxxt.dao.EmpDao;
import com.yjxxt.dao.IDeptDao;
import com.yjxxt.pojo.Dept;
import com.yjxxt.pojo.Emp;
import com.yjxxt.pojo.EmpAndDept;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Author Ben JiMi
 * @Date 2025/8/4 11:36
 * @Version 1.0
 */
public class Main {
    static SqlSessionFactory sqlSessionFactory = null;
    static {
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
             inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }
    public static void main(String[] args) throws IOException {
//        testInsert();
//    }


//        SqlSession session = sqlSessionFactory.openSession(true);
//        EmpDao empDao = session.getMapper(EmpDao.class);

//        List<EmpAndDept> ead = empDao.selectEmpAndDept();
//        for (EmpAndDept empAndDept : ead) {
//            System.out.println(empAndDept);
//        }
//        Emp emp = empDao.selectBySalMax();
//        System.out.println(emp);

//        int row = empDao.update(new Emp(7369, "老王", "CLERK", 7902, new java.util.Date(), 800, 0, 20));
//        System.out.println(row);
//        session.commit();


//        Emp emp3 = empDao.selectByEname("ALLEN");
//        System.out.println(emp3);

//        int row2 = empDao.delete(7369);

//        int row2 = empDao.deleteByChar("A");
//            Emp emp4 =new Emp(7369, "老王", "CLERK", 7902, new java.util.Date(), 800, 0, 20);
//            empDao.insert(emp4);
        //a.查找所有部门的名称和部门领导的方法,返回一个集合
//        List<Dept> deptList = mapper.selectAll();
//        for (Dept dept : deptList) {
//            System.out.println("名字：" + dept.getDname() + "                 职位：" +dept.getJob());
//        }
        //b.查找部门人数最多的方法,要求返回该部门的详细信息
    }
}

